﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ChineseSchool.Models.Hethong;
using ChineseSchool.BLL;

namespace ChineseSchool
{
    public partial class NewsDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblNewsContent.Text = LoadNewsContent();
                lblFacebook.Text = loadFacebook();
            }
        }

        public string LoadNewsContent()
        {
            string strNews = "";            
            M_News News = new M_News();
            if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
            {
                int NewsID = int.Parse(Request.QueryString["id"]);
                News = (new B_News()).Selectby_id(NewsID);
                if (News != null)
                {
                    strNews += "<h1><span>" + News.title.ToString() + "</span></h1>";
                    strNews += " <article class=\"alt\"> ";
                    strNews += " <div class=\"post-meta\"> ";
                    strNews += " <span class=\"post-date\">" + News.postDate.ToString() + "</span> &nbsp; ";
                    strNews += " Posted by <a rel=\"author\" title=\"Posts by admin\" href=\"#\">admin</a>";
                    strNews += " </div><div class=\"post-excerpt\">";
                    strNews += " <p>" + News.newsContent.ToString() + "</p>";
                    strNews += " </div></article>";

                    Page.Title = "" + News.title.ToString() + "";
                    Page.MetaDescription = "" + News.title.ToString() + "";
                    Page.MetaKeywords = "" + News.title.ToString() + "";
                }
                else
                {
                    Page.Title = "Học tiếng trung hiệu quả";                    
                }                
            }
            return strNews;
        }

        public string loadFacebook()
        {
            string strFacebook = "";
            if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
            {
                int NewsID = int.Parse(Request.QueryString["id"]);
                M_News M_News = (new B_News()).Selectby_id(NewsID);
                string Title = M_News.title.ToString();
                string curURL = Util.MakeLinkNewsDetail(NewsID.ToString(), Encode.Uni2KD(Title));                
                string share = "http://www.facebook.com/share.php?u=" + curURL + ";";
                if (curURL != "")
                {
                    //strFacebook += "<div class=\"fb-like\" data-href=\"" + curURL + "\" data-send=\"true\" data-width=\"660\" data-show-faces=\"true\">";
                    //strFacebook += "</div>";
                    //strFacebook += "<div>";
                    //strFacebook += "<a href=\"" + share + "\" onclick=\"return fbs_click()\" target=\"_blank\" class=\"fb_share_link\">";
                    //strFacebook += "Chia sẻ trên Facebook</a>";
                    //strFacebook += "</div>";
                    strFacebook += "<div class=\"fb-comments\" data-href=\"" + curURL + "\" data-width=\"660\" data-num-posts=\"10\">";
                    strFacebook += "</div>";
                }
            }
            return strFacebook;
        }
    }
}